package com.wwwarehouse.taskcenter.fragment.inventory_query;

import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.custom_widget.progressbar.HorizontalProgressView;
import com.wwwarehouse.taskcenter.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @创建者 chenchao.
 * @创建时间 2017/8/30 20:06
 * @描述 ${TODO}
 */
public class MoreInventoryFragment extends BaseFragment {

    private View mView;
    private ListView mLvMoreInv;
    private List mList;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_more_inventory, container, false);
        return mView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mLvMoreInv = (ListView) mView.findViewById(R.id.lv_more_inv);
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof MoreInventoryFragment) {
            mActivity.setTitle(getString(R.string.more_inventory));
        }
    }

    @Override
    public void requestDatas() {
        //得到前一个页面的集合
        mList = new ArrayList();
    }

    class MoreInvAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return mList.size();
        }

        @Override
        public Object getItem(int position) {
            return mList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            final ViewHolder viewHolder;
            if (convertView == null) {
                viewHolder = new ViewHolder();
                convertView = parent.inflate(mActivity, R.layout.item_more_inv, null);
                viewHolder.mTvOnvName = (TextView) convertView.findViewById(R.id.tv_inv_name);
                viewHolder.mHpInv = (HorizontalProgressView) convertView.findViewById(R.id.hpv_inv);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }

            viewHolder.mTvOnvName.setText("");


            viewHolder.mHpInv.setProgressAndTextColor(getResources().getColor(R.color.common_color_c1_337cff));
            ValueAnimator hpvAnimator = ValueAnimator.ofInt(0, viewHolder.mHpInv.getProgress());
            hpvAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animator) {
                    //获得当前动画的进度值，整型，1-100之间
                    int currentValue = (Integer) animator.getAnimatedValue();
                    viewHolder.mHpInv.setProgress(currentValue);
                }
            });
            hpvAnimator.setDuration(1000);
            hpvAnimator.start();
            return convertView;
        }
    }

    static class ViewHolder{
        public TextView mTvOnvName;
        private HorizontalProgressView mHpInv;
    }
}
